package com.ruoyi.web.controller.disasterAssessment;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.disasterassessment.domain.DisasterEvaluatingReport;
import com.ruoyi.disasterassessment.dto.ContentDto;
import com.ruoyi.disasterassessment.dto.DisasterEvaluatingReportDto;
import com.ruoyi.disasterassessment.service.IDisasterEvaluatingReportService;
import com.ruoyi.disasterassessment.vo.DisasterEvaluatingReportVo;
import com.ruoyi.disasterassessment.vo.ReportAllVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 灾害评估报告Controller
 * 
 * @author hcc
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/disasterassessment/report")
public class DisasterEvaluatingReportController extends BaseController
{
    @Autowired
    private IDisasterEvaluatingReportService disasterEvaluatingReportService;

    /**
     * 查询灾害评估报告列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(DisasterEvaluatingReport disasterEvaluatingReport)
    {
        startPage();
        List<DisasterEvaluatingReport> list = disasterEvaluatingReportService.selectDisasterEvaluatingReportList(disasterEvaluatingReport);
        return getDataTable(list);
    }

    /**
     * 导出灾害评估报告列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:export')")
    @Log(title = "灾害评估报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DisasterEvaluatingReport disasterEvaluatingReport)
    {
        List<DisasterEvaluatingReport> list = disasterEvaluatingReportService.selectDisasterEvaluatingReportList(disasterEvaluatingReport);
        ExcelUtil<DisasterEvaluatingReport> util = new ExcelUtil<DisasterEvaluatingReport>(DisasterEvaluatingReport.class);
        util.exportExcel(response, list, "灾害评估报告数据");
    }

    /**
     * 获取灾害评估报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(disasterEvaluatingReportService.selectDisasterEvaluatingReportById(id));
    }

    /**
     * 新增灾害评估报告
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:add')")
    @Log(title = "灾害评估报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DisasterEvaluatingReport disasterEvaluatingReport)
    {
        return toAjax(disasterEvaluatingReportService.insertDisasterEvaluatingReport(disasterEvaluatingReport));
    }

    /**
     * 修改灾害评估报告
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:edit')")
    @Log(title = "灾害评估报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DisasterEvaluatingReport disasterEvaluatingReport)
    {
        return toAjax(disasterEvaluatingReportService.updateDisasterEvaluatingReport(disasterEvaluatingReport));
    }

    /**
     * 删除灾害评估报告
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:remove')")
    @Log(title = "灾害评估报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(disasterEvaluatingReportService.deleteDisasterEvaluatingReportByIds(ids));
    }
    /**
     * 查询当天灾害评估报告列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:list')")
    @GetMapping("/listByNew")
    public TableDataInfo listByNew(@RequestBody DisasterEvaluatingReportVo vo) {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<DisasterEvaluatingReportDto> list = disasterEvaluatingReportService.getListByNew(vo);
        return getDataTable(list);
    }
    /**
     * 查询灾害评估报告通过faceId
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:query')")
    @GetMapping("/listByFaceId/{faceId}")
    public AjaxResult listByFaceId(@PathVariable("faceId") String faceId) {
        List<DisasterEvaluatingReportDto> list = disasterEvaluatingReportService.getListByFaceId(faceId);
        return success(list);
    }
    /**
     * 查询灾害评估报告pageList
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:list')")
    @GetMapping("/pageList")
    public PageInfo<DisasterEvaluatingReportDto> pageList(@RequestBody DisasterEvaluatingReportVo vo) {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<DisasterEvaluatingReportDto> list = disasterEvaluatingReportService.getDisasterEvaluatingReportList(vo);
        PageInfo<DisasterEvaluatingReportDto> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 获取灾害评估报告详细内容
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:query')")
    @GetMapping("/getLoadById/{id}")
    public AjaxResult getLoadById(@PathVariable("id") Long id) {
        List<ContentDto> contentDtoList = disasterEvaluatingReportService.getLoadById(id);
        return success(contentDtoList);
    }
    /**
     * 查询灾害评估报告reportAll
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:report:list')")
    @GetMapping("/reportAll")
    public TableDataInfo reportAll(@RequestBody ReportAllVo vo) {
        //TODO
        List<List<ContentDto>> list = disasterEvaluatingReportService.getReportAll(vo);
        return getDataTable(list);
    }
}
